<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;


use app\adminapi\controller\AuthController;
use app\services\car\CarOccupyTimeServices;
use think\facade\App;

/**
 * Class CarOccupyTime
 * @package app\adminapi\controller\v1\car
 */
class CarOccupyTime extends AuthController
{
    public function __construct(App $app,CarOccupyTimeServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }

    /**
     * 列表
     * @return mixed
     */
    public function getList(){
        $where = $this->request->getMore([
            ['keyword','']
        ]);
        $admin = $this->request->adminInfo();
        if($admin['store_id']) $where['place_id'] = $admin['store_id'];
        return app('json')->success($this->services->getList($where,true));
    }

    /**
     * 保存
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function occupyTimeSave(){
        $data = $this->request->postMore([
            ['id',0],
            ['car_id',0],
            ['order_id',0],
            ['occupy_type',0],
            ['start_date',''],
            ['start_time',''],
            ['end_date',''],
            ['end_time',''],
            ['remark',''],
        ]);
        return app('json')->success($this->services->occupyTimeSave((int)$data['id'],$data));
    }

    /**
     * 获取一条记录
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOccupyTimeInfo(){
        $data = $this->request->getMore([
            ['id',''],
        ]);
        if(!$data['id']) return app('json')->fail('参数错误');
        return app('json')->success($this->services->getOccupyTimeInfo($data['id']));
    }

    /**
     * 查看详情
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function viewDetailsInfo(){
        $data = $this->request->getMore([
            ['car_id',''],
            ['year',''],
            ['month',''],
        ]);
        if(!$data['car_id']) return app('json')->fail('参数错误');
        return app('json')->success($this->services->viewDetailsInfo($data));
    }
    /**
     * 删除
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function delete(){
        $data = $this->request->getMore([
            ['id', 0],
        ]);
        if (!$data['id']) return app('json')->fail('参数错误');
        return app('json')->success($this->services->delOccupy((int)$data['id']));
    }
}
